package demo;

public class Test {
    public static void duplicateZeros(int[] arr) {
        int prev=0;
        int cur=1;

        while(cur<arr.length){
            if(arr[prev]==0){
                for(int i=arr.length-2;i>=cur;i--){
                    arr[i]=arr[i+1];
                }
                arr[cur]=0;
            }
            cur++;
            prev++;
        }
    }

    public static void main(String[] args) {
        int[] arr={1,0,2,3,0,4,5,0};
        duplicateZeros(arr);
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }
    }
}
